//
//  MKUpDateTableViewCell.m
//  ManKeCartoon
//
//  Created by 邹功梁 on 15/10/23.
//  Copyright © 2015年 ManKe. All rights reserved.
//

#import "MKUpDateTableViewCell.h"
#import "MKBaseHeader.h"
@implementation MKUpDateTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(105 * WIDTH, 15 * HEIGHT, SCREEN_WIDTH - 105 * WIDTH, 20 * HEIGHT)];
        _titleLabel.textColor = [UIColor grayColor];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.font = [UIFont systemFontOfSize:18.];
        
        _artist_nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(105 * WIDTH, 50 * HEIGHT, SCREEN_WIDTH - 105 * WIDTH, 10 * HEIGHT)];
        _artist_nameLabel.textColor = [UIColor lightGrayColor];
        _artist_nameLabel.textAlignment = NSTextAlignmentLeft;
        _artist_nameLabel.font = [UIFont systemFontOfSize:12.];
        
        _lastupLabel = [[UILabel alloc] initWithFrame:CGRectMake(105 * WIDTH, 70 * HEIGHT, SCREEN_WIDTH - 105 * WIDTH, 10 * HEIGHT)];
        _lastupLabel.textAlignment = NSTextAlignmentLeft;
        _lastupLabel.textColor = [UIColor lightGrayColor];
        _lastupLabel.font = [UIFont systemFontOfSize:12.];
        
        _grade_aveLabel = [[UILabel alloc] initWithFrame:CGRectMake(170 * WIDTH, 90 * HEIGHT, 20 * WIDTH, 10 * HEIGHT)];
        _grade_aveLabel.textAlignment = NSTextAlignmentLeft;
        _grade_aveLabel.textColor = [UIColor orangeColor];
        _grade_aveLabel.font = [UIFont systemFontOfSize:10.];
        
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(105 * WIDTH, 120 * HEIGHT - 1, SCREEN_WIDTH - 105 * WIDTH, 1)];
        [_lineView setBackgroundColor:[UIColor colorWithRed:0.87 green:0.87 blue:0.87 alpha:1]];
        
        [self.contentView addSubview:_titleLabel];
        [self.contentView addSubview:_artist_nameLabel];
        [self.contentView addSubview:_lastupLabel];
        [self.contentView addSubview:_grade_aveLabel];
        [self.contentView addSubview:_lineView];
    }
    return self;
}
- (void)setUpDateModel:(MKUpDateModel *)model
{
    for (id view in self.contentView.subviews) {
        if ([view isKindOfClass:[_starGrade class]]) {
            [view removeFromSuperview];
        }
    }
    
    _comicImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20 * WIDTH, 10 * HEIGHT, 75 * WIDTH, 100 * HEIGHT)];
    [_comicImageView sd_setImageWithURL:[NSURL URLWithString:model.cover_url]];
    [self.contentView addSubview:_comicImageView];
    
    _titleLabel.text = model.title;
    _artist_nameLabel.text = [NSString stringWithFormat:@"作者: %@", model.artist_name];
    _lastupLabel.text = [NSString stringWithFormat:@"更新至%@", model.lastup];
    _grade_aveLabel.text = model.grade_ave;
    
    for (int i = 0; i < 5; i++) {
        _starGrade = [[UIImageView alloc] initWithFrame:CGRectMake(105 * WIDTH + 12 * WIDTH * i, 90 * HEIGHT, 10 * WIDTH, 10 * HEIGHT)];
        if (i < model.grade.integerValue / 10) {
            [_starGrade setImage:[UIImage imageNamed:@"detail_star_full@2x.png"]];
        }
        else
        {
            [_starGrade setImage:[UIImage imageNamed:@"detail_star_none@2x.png"]];
        }
        [self.contentView addSubview:_starGrade];
    }
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
